package com.cy.pj.common.service;

import com.cy.pj.common.cache.Cache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

@Service
public class CacheService {
    //@Autowired    // 这种方式用得最多
    //@Qualifier("softCache")
    private Cache cache;// 耦合于抽象，另外还有耦合于工厂

    //public CacheService() {
    //    System.out.println("CacheService.CacheService   111");
    //}
    //
    //@Autowired //可以描述构造方法,只有这一个构造函数时，这里也可以不写@Autowired
    //public CacheService(@Qualifier("softCache") Cache cache) {
    //    System.out.println("CacheService.CacheService    333");
    //    this.cache = cache;
    //}

    @Autowired
    public void setCache(@Qualifier("softCache") Cache cache) {
        this.cache = cache;
    }

    public Cache getCache() {
        return cache;
    }
}
